<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2-返回元素是偶数的数组</title>
</head>
<body>
    <script type="text/javascript">
        
        var arr = [1,3,5,7,10,20,12];
        console.log("原生JS写法.............");
        var newArr = [];

        //循环
        arr.forEach(function(val,index,arr){
            if(val%2==0){
                newArr.push(val);
            }
        });
        console.log(newArr);
        console.log('ES5..........filter');
        /**
         * arr.filter(function(val,index,arr){});
         * 最终返回新的数组
         */
        var esArr = arr.filter(function(val,index,arr){
            return val%2 == 0;
        });
        console.log(esArr);


    </script>
</body>
</html>